#pragma once

#include "DownLoadTaskMgr.h"
class CDownLoad :
	public  IDownLoad,
	public  IDownLoadTaskPoint,
	private CUnknownImp
{
public:
	UNKNOWN_IMP2_(IDownLoad , IDownLoadTaskPoint);
	STDMETHOD(init_class)(IMSBase* pRot , IMSBase* pOuter)
	{
		RASSERT(pRot , E_INVALIDARG);
		m_pRot = pRot;
		return S_OK;
	}
public:
	CDownLoad(void);
	~CDownLoad(void);


	//IDownLoad
	STDMETHOD(Init)(IDownLoadNotify* pDlNotify) ;
	STDMETHOD(UnInit)() ;

	STDMETHOD(CreateDownloadTask)(const download_info& dlInfo,sha1_hash& urlhash) ;
	STDMETHOD(DestoryDownLoadTask)(const sha1_hash& rulhash);
	STDMETHOD(Pause)       (const sha1_hash& urlhash);      // urlhash = 0xfffffff....ff   === pause all task
	STDMETHOD(Resume)      (const sha1_hash& urlhash);	
	STDMETHOD(Stop)        (const sha1_hash& urlhash, BOOL remove_files = FALSE);

	
	STDMETHOD(GetStat)     (const sha1_hash& urlhash, StateMessageID statid, void* data, int nlen);
	STDMETHOD(SetStat)     (const sha1_hash& urlhash, StateMessageID statid, void* data, int nlen);

	STDMETHOD(SetOption)(P2POption option, void * data, int nlen);
	STDMETHOD(GetOption)(P2POption option, void * data, int nlen);

	STDMETHOD_(IDownLoadTask*,GetDownLoadTask)(const sha1_hash& urlhash);
	STDMETHOD(EnumTask)();

	STDMETHOD(OnDownLoadTaskNotify)(const sha1_hash& urlhash, NotifyMessageID atype, WPARAM wp, LPARAM lp);
private:
	UTIL::com_ptr<IMscomRunningObjectTable> m_pRot;
	UTIL::com_ptr<IDownLoadNotify> m_pDlNotify;

private:
	CDownLoadTaskMgr m_DownLoadTaskMgr;
};
